package com.itheima.service.impl;

import com.itheima.dto.LoginRequest;
import com.itheima.exception.BusinessException;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.service.LoginService;
import com.itheima.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private EmpMapper empMapper;
    @Override
    public UserInfoVo login(LoginRequest request) {

        Emp emp=empMapper.findByUserNameAndPassword(request.getUsername(),request.getPassword());
        if (emp==null) {
            throw new BusinessException("用户名或密码错误");
        }


        return new UserInfoVo(emp.getId(),emp.getUsername(),emp.getName(),emp.getImage(),null);
    }
}
